Stored Procedures [dbo].[sp_asi_sp_pkeys]
Properties
PropertyValue
ANSI Nulls OnYes
Quoted Identifier OnYes
Parameters
NameData TypeMax Length (Bytes)
@table_namevarchar(96)96
@table_ownervarchar(96)96
@table_qualifiervarchar(96)96
Permissions
TypeActionOwning Principal
GrantExecuteIMIS
SQL Script
CREATE PROCEDURE sp_asi_sp_pkeys(
                    @table_name        varchar(96),
                    @table_owner     varchar(96) = null,
                    @table_qualifier varchar(96) = null )
        as
            DECLARE @table_id            int
            DECLARE @full_table_name    varchar(255) /* 2*128 + 1 */
            if @table_qualifier is not null
            begin
                if db_name() <> @table_qualifier
                begin    /* If qualifier doesn't match current database */
                    raiserror (15250, -1,-1)
                    return
                end
            end
            if @table_owner is null
            begin    /* If unqualified table name */
                SELECT @full_table_name = @table_name
            end
            else
            begin    /* Qualified table name */
                if @table_owner = ''
                begin    /* If empty owner name */
                    SELECT @full_table_name = @table_owner
                end
                else
                begin
                    SELECT @full_table_name = @table_owner + '.' + @table_name
                end
            end
            /*    Get Object ID */
            SELECT @table_id = object_id(@full_table_name)
            select
                TABLE_QUALIFIER = convert(varchar(96),db_name()),
                TABLE_OWNER = convert(varchar(96),user_name(o.uid)),
                TABLE_NAME = convert(varchar(96),o.name),
                COLUMN_NAME = convert(varchar(96),c.name),
                KEY_SEQ = convert(smallint,c1.colid),
                PK_NAME = convert(varchar(96),i.name)
            from
                sysindexes i, syscolumns c, sysobjects o, syscolumns c1
            where
                o.id = @table_id
                and o.id = c.id
                and o.id = i.id
                and (i.status & 0x800) = 0x800
                and c.name = index_col (@full_table_name, i.indid, c1.colid)
                and c1.colid <= i.keycnt    /* create rows from 1 to keycnt */
                and c1.id = @table_id
            order by 1, 2, 3, 5

GO
GRANT EXECUTE ON  [dbo].[sp_asi_sp_pkeys] TO [IMIS]
GO
Uses